package com.shenzhenai.jetpackcomposelayouts

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.VerticalDivider
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.shenzhenai.jetpackcomposelayouts.ui.theme.DN_Compose_LearnTheme

/**
 * @author huangzehui
 * @date 4/8/2025 下午11:29 周一
 * @description 布局多次测量(Intrinsics)
 */

@Composable
fun TowTextsSample() {
    DN_Compose_LearnTheme {
        Scaffold { innerPadding ->
            TwoTexts(modifier = Modifier.padding(innerPadding))
        }
    }
}


@Composable
fun TwoTexts(modifier: Modifier) {
    Row(modifier = modifier.height(IntrinsicSize.Min)) {
        Text(
            text = "Hi", modifier = Modifier
                // 设置权重
                .weight(1f)
                .padding(start = 12.dp)
                // 包裹内容对其方式
                .wrapContentWidth(Alignment.Start)
        )

        // 这个线的高度会拓展到整个屏幕
        // 要解决的话，使用 IntrinsicSize.Min/IntrinsicSize.Max 属性即可
        VerticalDivider(
            color = Color.Black,
            modifier = Modifier
                // 让高度填充父视图的高度
                .fillMaxHeight()
                // 设置宽度
                .width(1.dp)
        )

        Text(
            text = "There", modifier = Modifier
                // 设置权重
                .weight(1f)
                .padding(end = 12.dp)
                // 包裹内容对其方式
                .wrapContentWidth(Alignment.End)
        )

    }
}